package com.decent.web.system.service.impl;

import com.decent.common.bo.MessageBean;
import com.decent.web.system.dto.SystemGoodsDTO;
import com.decent.web.system.service.SystemGoodsService;
import com.decent.web.system.vo.SystemGoodsVO;
import com.decent.web.system.dao.SystemGoodsDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: decent Gjh
 * @date: 2022/10/25/18:35
 * @description:
 */
@Service
@Slf4j
public class SystemGoodsServiceImpl implements SystemGoodsService {
    private final SystemGoodsDao goodsDao;

    public SystemGoodsServiceImpl(SystemGoodsDao goodsDao) {
        this.goodsDao = goodsDao;
    }

    /**
     * 查找商品
     * @param goodsDTO 商品信息
     * @return 是否成功
     */
    @Override
    public MessageBean selectGoods(SystemGoodsDTO goodsDTO) {
        List<SystemGoodsVO> classifies = goodsDao.selectGoods(goodsDTO);
        if (classifies==null||classifies.isEmpty()) {
            return MessageBean.success("暂无数据");
        }
        return MessageBean.success(classifies);
    }

    /**
     * 根据id查找商品
     * @param goodsId 商品id
     * @return 商品信息
     */
    @Override
    public MessageBean selectGoodsById(int goodsId) {
        SystemGoodsVO goods=goodsDao.selectGoodsById(goodsId);
        if (goods == null || goods.getId() == null || goods.getId() == 0){
            return MessageBean.fail("商品不存在");
        }
        return MessageBean.success(goods);
    }

    /**
     * 查找热门商品
     * @return 热门商品信息
     */
    @Override
    public MessageBean selectHotGoods() {
        List<SystemGoodsVO> goods = goodsDao.selectHotGoods();
        return MessageBean.success(goods);
    }

}
